home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news
- From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
- Newsgroups: comp.lang.c++
- Subject: Re: Using a Base constructor for a derived class
- Date: Tue, 16 Jan 1996 15:00:07 +0100
- Organization: Fachbereich Informatik, TH Darmstadt
- Message-ID: <30FBAF67.7DE14518@intellektik.informatik.th-darmstadt.de>
- References: <4ddui9$a14@felix.cc.gatech.edu>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b5 (X11; I; SunOS 4.1.3 sun4m)
-
- Matthew W. Culbreth wrote:
- >
- > I have a base class with a constructor. This class is never used
- > in my application. I have three classes derived from this class.
- >
- > When I create an instant of one of the derived class, I want to use the
- > constructor from the base class. The compiler is stating that it can't find
- > the constructor for the arguments passed for any of the derived classes.
- > Are constructors inherited the same as member functions?
- >
-
- If a base-class doesn't provide a default-ctor (ie. the ctor that
- takes no arguments) you have to use the initializer list in the
- derived class to call the appropriate base-class ctor. Example:
-
- class Base {
- public:
- Base(int i) { ...}
- };
-
- class Der : public Base {
- public:
- Der() : Base(4711) {}
- };
-
- The base-class needs an integer argument to get properly initialized
- and the initializer list of the derived class allows you to pass the
- necessary value.
-
- Enno
-